• File: hub_import_done_maintain_get.php
  • Full Path: C:/htdocs/REEFTintegrationLog_test/REEFTintegrationLog/saved/hub_import_done_maintain_get.php
  • Date Modified: 04/30/2025 7:56 AM
  • File size: 9.3 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php
//======================================================================================
//
// Function: Get hub_config => DATA-HUB - IFS log
//
// Programmer: JKJ
// Date      : 2024-10-14
//
// Copyright Reeft A/S (c) - 2024
//======================================================================================

// datatables parameters:
// https://datatables.net/manual/server-side

//======================================================================================
// General config
//======================================================================================
	include "config/config.php";

//======================================================================================
// Set language
//======================================================================================

	include "include/set_language.php";

//======================================================================================
// Get input
//======================================================================================

	if (isset($_REQUEST["FILE_NAME"])) {
		$FILE_NAME = $_REQUEST["FILE_NAME"];
	} else {
		$FILE_NAME = '';
	}

	if (isset($_REQUEST["what_to_call"])) {
		$what_to_call = $_REQUEST["what_to_call"];
	} else {
		$what_to_call = '';
	}

	if (isset($_REQUEST["dir_name"])) {
		$dir_name = $_REQUEST["dir_name"];
	} else {
		$dir_name = '';
	}

	if (isset($_REQUEST["number_of_files"])) {
		$number_of_files = $_REQUEST["number_of_files"];
	} else {
		$number_of_files = '';
	}

	if (isset($_REQUEST["ifs_file_path"])) {
		$ifs_file_path = $_REQUEST["ifs_file_path"];
	} else {
		$ifs_file_path = '';
	}

	if (isset($_REQUEST["fromdate"])) {
		$fromDate = $_REQUEST["fromdate"];
	} else {
		$fromDate = '0001-01-01';
	}

	if (isset($_REQUEST["todate"])) {
		$toDate = $_REQUEST["todate"];
	} else {
		$toDate = '9999-12-31';
	}

	if (isset($_REQUEST["fromdatetime"])) {
		$fromDateTime = $_REQUEST["fromdatetime"];
	} else {
		$fromDateTime = '0001-01-01';
	}

	if (isset($_REQUEST["todatetime"])) {
		$toDateTime = $_REQUEST["todatetime"];
	} else {
		$toDateTime = '9999-12-31';
	}
	
	if (isset($_REQUEST["super_search_arg"])) {
		$super_search_arg = $_REQUEST["super_search_arg"];
	} else {
		$super_search_arg = '';
	}

	//===============================================================
	// Pagination fields "local"/datatables
	//===============================================================

	if (isset($_REQUEST["rpyOffSet"])) {
		$rpyOffSet = $_REQUEST["rpyOffSet"];
	} else {
		$rpyOffSet = 0;
	}

	if (isset($_REQUEST["rpyPageSize"])) {
		$rpyPageSize = $_REQUEST["rpyPageSize"];
	} else {
		$rpyPageSize = 0;
	}

	if (isset($_REQUEST["rpyPageGoTo"])) {
		$rpyPageGoTo = $_REQUEST["rpyPageGoTo"];
	} else {
		$rpyPageGoTo = 0;
	}

	//===============================================================
	// Datatables input, will overrule "orgainal" fields if found
	//===============================================================

	if (isset($_REQUEST["start"])) {
		$dataTablesOffset = $_REQUEST["start"];
	} else {
		$dataTablesOffset = 0;
	}

	if (isset($_REQUEST["length"])) {
		$dataTablesPageLength = $_REQUEST["length"];
	} else {
		$dataTablesPageLength = 0;
	}

	if (isset($_REQUEST["search"]["value"])) {
		$search_arg = $_REQUEST["search"]["value"];
	} else {
		$search_arg = '';
	}

	if (isset($_REQUEST['draw'])) {
		$draw = $_REQUEST['draw'];
	} else {
		$draw = 1;
	}

	if (isset($_REQUEST["order"][0])) {

		$rpyOrderColumn = '';

		foreach ($_REQUEST["order"] as $key => &$tmpArr) {



			$order_column_index = $tmpArr["column"];
			$order_column_dir 	= $tmpArr["dir"];

			if ($key == 0) $rpyOrderColumn = $_REQUEST["columns"][$order_column_index]["data"] . "|" . strtoupper($order_column_dir);
			else $rpyOrderColumn .= "," . $_REQUEST["columns"][$order_column_index]["data"] . "|" . strtoupper($order_column_dir);

		}
	} else {
		$rpyOrderColumn = '';
	}

	// echo $rpyOrderColumn . ' ' . $order_column_dir;
	// exit;

	//$search_arg = urldecode($search_arg);

	$search_arg = str_replace(' ', "|", $search_arg);

//======================================================================================
// Get input
//======================================================================================

	if ( $dataTablesPageLength > 0 ) {
		$rpyPageSize = $dataTablesPageLength;
	}


	if ( $dataTablesOffset > 0 ) {
		$rpyOffSet = $dataTablesOffset;
	}

//======================================================================================
// Get session variables
//======================================================================================
	include "include/getsession.php";

//======================================================================================
// Set language
//======================================================================================
	include "include/set_language.php";

//======================================================================================
// Connect to SQLite database in file
//======================================================================================

	$entries_found					= 0;

	$returnCode 					= '99';
	$returnMsg 						= 'No data found';

	$currentDate = date('Y-m-d');
	$currentTime = date('H:i:s');

//======================================================================================
// Set header
//======================================================================================

	header('Content-Type: application/json;charset=utf-8');

//======================================================================================
// Get time stamp
//======================================================================================
	$timeStamp = '';
	if ( $timeStamp == '' ) {
		$now = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''));
		$timeStamp = $now->format("Y-m-d H:i:s");
	}


	$data = array(
		"timestamp" 		=> $timeStamp,
		"rpyPageGoTo" 		=> $rpyPageGoTo,
		"rpyOffSet" 		=> $rpyOffSet,
		"rpyPageSize" 		=> $rpyPageSize,
		"rpyOrderColumn" 	=> $rpyOrderColumn,
		"FILE_NAME" 		=> $FILE_NAME,
		"what_to_call"		=> $what_to_call,
		"dir_name"			=> $dir_name,
		"number_of_files"	=> $number_of_files,
		"ifs_file_path"		=> $ifs_file_path,
		"fromdate"			=> $fromDate,
		"todate"			=> $toDate,
		"fromdatetime"		=> $fromDateTime,
		"todatetime"		=> $toDateTime,
		"super_search_arg"	=> $super_search_arg,
		"draw" 				=> $draw
		);

//======================================================================================
// Make call to API somewhere
//======================================================================================

	$jsonData = json_encode($data);
	//header('Content-Type: application/json');

	$json_pretty = json_encode(json_decode($jsonData), JSON_PRETTY_PRINT);
	// echo $json_pretty;
	// echo "<br>";
	// echo $url;

	$headers = array(
         "Content-type: Content-Type:application/json",
		 "User-Agent: DATA-HUB 1.0",
         "APIKEY: $DFT_API_KEY"
     );

	$parms 	= '?'
			. 'rpyPageGoTo=' 		. $rpyPageGoTo
			. '&rpyOffSet=' 		. $rpyOffSet
			. '&rpyPageSize=' 		. $rpyPageSize
			. '&rpySearchArg=' 		. $search_arg
			. '&rpyOrderColumn='	. $rpyOrderColumn
			. '&FILE_NAME=' 		. $FILE_NAME
			. '&what_to_call='		. $what_to_call
			. '&dir_name='			. $dir_name
			. '&number_of_files='	. $number_of_files
			. '&ifs_file_path='		. $ifs_file_path
			. '&fromdate='			. $fromDate
			. '&todate='			. $toDate
			. '&fromdatetime='		. $fromDateTime			
			. '&todatetime='		. $toDateTime
			. '&super_search_arg='	. $super_search_arg
			. '&draw=' 				. $draw
			;


	// Set URL
	$url = $DFT_WEBSERVICE_URL_DATAHUB . '/' . 'HUB_IMPLOG';

	// Add parms
	$url = $url . $parms;

	// echo $url;
	// exit;

	// Create a new cURL resource
	$ch = curl_init($url);

	// Attach encoded JSON string to the POST fields
	curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

	// Set the content type to application/json
	//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );

	// Return response instead of outputting
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_POST, false);
	//curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' );
	curl_setopt($ch, CURLOPT_HEADER, false);    // we do not need headers
	curl_setopt($ch, CURLOPT_NOBODY, false);    // we don't need body

	// Execute the GET request
	$result = curl_exec($ch);

	$ary	= curl_getinfo($ch);

	// Close cURL resource
	curl_close($ch);

	$data = json_decode($result, true);

	$returnResult = [];


	$returnResult["header"]				= $data['header'];
	//$returnResult["header_buttons"]		= $data['header_buttons'];
	$returnResult["draw"]				= intval( $draw );
	$returnResult["recordsTotal"]		= intval( $data['header']['rpyTableRecordsFoundWithFilter'] );
	$returnResult["recordsFiltered"]	= intval( $data['header']['rpyTotalRecordsFound'] );
	$returnResult["data"]				= array();
	$returnResult["data"]				= $data['data'];


	// $mySQL = $data['header']['SQLstatementMAIN'];
	// error_log(date("Y-m-d H:i:s") . $mySQL . " \n ",3,"__log_jan.txt");

	echo json_encode($returnResult);

?>